<template>
  <div class="container">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
      <el-breadcrumb separator="">
        <el-breadcrumb-item>
          <div class="div1">订单管理</div>
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <div class="div2" @click="toOrder">确定收货</div>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 面包屑导航 -->
    <div class="orderInfo">
      <div class="title">
        <span>订单信息</span>
      </div>
      <div class="content" v-if="!is_null(content)">
        <div class="contentTemp">
          <div class="fontTemp">
            <span class="span">原单编号: {{ content.orderId }}</span>
            <span class="span">订单编号: {{ content.returnOrderId }}</span>
            <span class="span">订单状态: {{ content.returnStatusName }}</span>
            <div class="span" style="display:inline-block;">
              <span class="span1">时 间</span>
              <span>:{{ content.applyTime }}</span>
            </div>
            <div class="span" style="display:inline-block;">
              <span class="span1">客 服:</span>
              <span>{{ content.applyName }}</span>
            </div>
          </div>
        </div>
        <div class="contentTemp">
          <div class="fontTemp">
            <span class="span"
              >客户信息: {{ content.customerName }} {{ content.customerPhone }}
              {{ content.userAddress }}</span
            >
          </div>
        </div>
        <div class="contentTemp">
          <div class="fontTemp">
            <span class="span"
              >收货信息: {{ content.addressName }} {{ content.addressPhone }}
              {{ content.rejectAddress }}</span
            >
          </div>
        </div>
        <div class="contentTemp">
          <div class="fontTemp">
            <span class="span" v-if="!is_null(content.comment)"
              >备注: {{ content.comment }}</span
            >
            <span class="span" v-else>备注:无</span>
          </div>
        </div>
        <div class="contentTemp" v-if="!is_null(content.logisticsCompany)">
          <div class="fontTemp">
            <span class="span"
              >包裹单号: {{ content.logisticsCompany }}
              {{ content.parcelNumber }}</span
            >
          </div>
        </div>
      </div>
    </div>
    <div class="goodDetail">
      <div class="title">商品详情</div>
      <div class="content">
        <div class="title" style="border:0;">商品</div>
        <el-table
          :data="content.orderReturnCommodityList"
          :header-cell-style="{ color: '#333', textAlign: 'center' }"
          style="width: 100%"
        >
          <el-table-column prop="brand" label="品牌"> </el-table-column>
          <el-table-column width="200" prop="commodityName" label="商品名称">
          </el-table-column>
          <el-table-column prop="number" label="退货数量"> </el-table-column>
          <!-- <el-table-column prop="waitNumber" label="可退数量">
					</el-table-column> -->
          <el-table-column label="仓库收货" width="200">
            <template slot-scope="scope">
              <div class="optain">
                <div class="inputDeal">
                  <span>已收</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.receivedNum"
                      :value="scope.row.receivedNum"
                      @change="changCountRecived(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.receivedNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeRecived(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeRecived(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>

                <div class="inputDeal">
                  <span>破损</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.damagedNum"
                      :value="scope.row.damagedNum"
                      @change="changeCountDamage(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.damagedNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeDamage(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeDamage(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>

                <div class="inputDeal">
                  <span>漏件</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.missingNum"
                      :value="scope.row.missingNum"
                      @change="changeCountMissing(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.missingNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeMissing(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeMissing(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <!-- 物流操作 -->
          <el-table-column label="单价">
            <template slot-scope="scope"> ￥{{ scope.row.price }} </template>
          </el-table-column>
          <el-table-column prop="specificationName" label="规格">
          </el-table-column>

          <el-table-column label="退货小计">
            <template slot-scope="scope"> ￥{{ scope.row.total }} </template>
          </el-table-column>
        </el-table>
        <div class="operatingStatus" style="border:0;">赠品</div>
        <el-table
          :data="content.orderReturnComplimentaryList"
          :header-cell-style="{ color: '#333', textAlign: 'center' }"
          style="width: 100%"
        >
          <el-table-column prop="brand" label="品牌"> </el-table-column>
          <el-table-column
            width="200"
            prop="complimentaryName"
            label="商品名称"
          >
          </el-table-column>
          <el-table-column prop="number" label="退货数量"> </el-table-column>
          <!-- <el-table-column prop="waitNumber" label="可退数量">
					</el-table-column> -->
          <!-- 物流操作 -->
          <el-table-column label="仓库收货" width="200">
            <template slot-scope="scope">
              <div class="optain">
                <div class="inputDeal">
                  <span>已收</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.receivedNum"
                      :value="scope.row.receivedNum"
                      @change="changCountRecivedZp(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.receivedNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeRecivedZp(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeRecivedZp(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>

                <div class="inputDeal">
                  <span>破损</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.damagedNum"
                      :value="scope.row.damagedNum"
                      @change="changeCountDamageZp(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.damagedNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeDamageZp(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeDamageZp(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>

                <div class="inputDeal">
                  <span>漏件</span>
                  <div class="numer">
                    <el-input
                      v-model="scope.row.missingNum"
                      :value="scope.row.missingNum"
                      @change="changeCountMissingZp(scope.row, scope.$index)"
                      :min="1"
                      :max="scope.row.missingNum"
                    >
                      <el-button
                        slot="prepend"
                        @click="changeMissingZp(scope.row, -1, scope.$index)"
                        ><i class="el-icon-minus"></i
                      ></el-button>
                      <el-button
                        slot="append"
                        @click="changeMissingZp(scope.row, 1, scope.$index)"
                        ><i class="el-icon-plus"></i
                      ></el-button>
                    </el-input>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <!-- 物流操作 -->

          <el-table-column label="单价">
            <template slot-scope="scope"> ￥{{ scope.row.price }} </template>
          </el-table-column>
          <el-table-column prop="specificationName" label="规格">
          </el-table-column>

          <el-table-column label="小计">
            <template slot-scope="scope"> ￥{{ scope.row.total }} </template>
          </el-table-column>
        </el-table>
        <div class="totalAll" v-if="!is_null(content)">
          <span>原单总计：共{{ content.orderNumber }}件</span>
          <!-- <span>运费：{{content.charge}}元</span> -->
          <span>赠品总价 ￥ {{ content.giftTotal }}</span>
          <span>商品总价 ￥ {{ content.goodsTotal }}</span>
          <span>应收金额 ￥ {{ content.orderMoney }}</span>
          <span>已收金额 ￥ {{ content.orderReceivedMoney }}</span>
          <span>待收金额 ￥ {{ content.orderAwaitIncomeMoney }}</span>
        </div>

        <div class="totalAll" v-if="!is_null(content)">
          <span>退货总计</span>
          <span>退货 {{ content.returnNumber }} 件</span>
          <span>总价 ￥ {{ content.returnMoney }}</span>
        </div>

        <div class="totalAll" v-if="!is_null(content)">
          <span>仓库收货总计</span>
          <span>已收 {{ receivedTogether }} 件</span>
          <span>破损 {{ damagedTogether }} 件</span>
          <span>漏件 {{ missingTogether }} 件</span>
          <span>已收货总价 ￥ {{ content.orderTotal }}</span>
        </div>

        <div class="total" v-if="!is_null(content)">
          <span>已收金额 ￥ {{ content.orderReceivedMoney }}</span>
        </div>
        <div class="total" v-if="!is_null(content)">
          <span>应退 ￥ {{ content.shouldReturnMoney }}</span>
        </div>
      </div>
    </div>
    <div class="remark">
      <div class="title">备注</div>
      <el-input
        type="textarea"
        :rows="2"
        placeholder="请输入内容"
        v-model="textarea"
      >
      </el-input>
    </div>
    <div style="height:70px;"></div>
    <div class="submit">
      <el-button
        type="primary"
        plain
        size="mini"
        style="width:100px;"
        @click="submitEvent(1)"
        >驳回</el-button
      >
      <el-button
        type="primary"
        size="mini"
        style="width:100px;"
        @click="submitEvent(2)"
        >确定收货</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      orderId: "",
      content: "",
      textarea: "",
      tableData: [],
      backNumTotal: 0,
      receivedTogether: 0,
      damagedTogether: 0,
      missingTogether: 0,
      packages: 0, //总(商品+赠品)件数
      jage: 0,
      logisticsCompany: "",
      logistCode: "",
      companys: [],
      together: 0,
      orginNumber: 0,
      returnOrderId: "",
    };
  },
  created() {
    this.id = this.$route.query.id;
    this.returnOrderId = this.$route.query.returnOrderId;
    this.fixDetail = this.$route.query.fixDetail;
    // if (this.jage == 1) {
    // 	this.logisticsExpress();
    // }
    this.detailAxios();
  },
  methods: {
    toOrder() {
      this.$router.push({
        name: "unusualOrder",
        query: {
          tabName: this.queryType.tabName,
        },
      });
    },
    /**
     * 详情
     * **/
    detailAxios() {
      this.axios
        .get(
          "/order/order/return/returnGoods/detail?id=" +
            this.id +
            "&fixDetail=" +
            2
        )
        .then((res) => {
          console.log(res);
          if (res.code == 0) {
            // 插入商品,赠品仓库默认的数据
            let goodsTotal = 0;
            let numbergoods = 0;
            for (let i = 0; i < res.data.orderReturnCommodityList.length; i++) {
              res.data.orderReturnCommodityList[i].receivedNum = 0; //已收
              res.data.orderReturnCommodityList[i].damagedNum = 0; //破损
              res.data.orderReturnCommodityList[i].missingNum = 0; //漏件
              goodsTotal += parseInt(
                res.data.orderReturnCommodityList[i].total
              );
              numbergoods += res.data.orderReturnCommodityList[i].number;
            }
            res.data.goodsTotal = goodsTotal;

            let giftTotal = 0;
            let giftNumber = 0;
            if (!this.is_null(res.data.orderReturnComplimentaryList)) {
              for (
                let i = 0;
                i < res.data.orderReturnComplimentaryList.length;
                i++
              ) {
                res.data.orderReturnComplimentaryList[i].receivedNum = 0; //已收
                res.data.orderReturnComplimentaryList[i].damagedNum = 0; //破损
                res.data.orderReturnComplimentaryList[i].missingNum = 0; //漏件
                giftTotal += Number(
                  res.data.orderReturnComplimentaryList[i].total
                );
                giftNumber += res.data.orderReturnComplimentaryList[i].number;
              }
            }
            res.data.giftTotal = giftTotal;
            this.packages = numbergoods + giftNumber;
            this.content = res.data;
          } else {
            this.$message.error(res.message);
          }
        });
    },
    /**
     * 详情
     * **/
    /**
     * 查询物流快递公司
     **/
    // logisticsExpress() {
    // 	this.axios.get("/sys/v1/common/by/group?groupId=courier_company", {
    // 		headers: {
    // 			isLoading: false
    // 		}
    // 	}).then(res => {
    // 		// console.log(res);
    // 		if (res.code == 0) {
    // 			this.companys = res.data;
    // 		} else {
    // 			this.$message.error(res.message)
    // 		}
    // 	})
    // },
    /**
     * 查询物流快递公司
     **/
    /**
     * 商品已收 破损 漏件 数量操作修改
     **/
    changCountRecived(row, index) {
      if (
        null == row.receivedNum ||
        row.receivedNum == "" ||
        (row.receivedNum != "number" && isNaN(row.receivedNum))
      ) {
        row.receivedNum = 0;
      } else if (row.receivedNum <= 0) {
        row.receivedNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.receivedNum > row.number) {
        row.receivedNum = 0;
        this.$message.warning("已收数不能大于原单数量");
      } else if (
        parseInt(row.receivedNum) + parseInt(row.missingNum) >
        row.number
      ) {
        row.receivedNum = 0;
        this.$message.warning("已收 + 漏件 不能大于原单数量");
      }

      this.$set(this.content.orderReturnCommodityList, index, {
        commodityId: row.commodityId,
        brand: row.brand,
        commodityName: row.commodityName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    changeRecived(row, type, index) {
      let addNum = parseInt(row.receivedNum) + parseInt(row.missingNum);
      if (type > 0) {
        if (row.receivedNum >= row.number) {
          this.$message.warning("已收数不能大于原单数量");
        } else if (addNum >= row.number) {
          this.$message.warning("已收+漏件 不能大于原单数量");
        } else {
          row.receivedNum++;
        }
      } else {
        row.receivedNum--;
        row.receivedNum > 0 ? row.receivedNum : (row.receivedNum = 0);
      }
      this.$set(this.content.orderReturnCommodityList, index, {
        commodityId: row.commodityId,
        brand: row.brand,
        commodityName: row.commodityName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    // 破损
    changeCountDamage(row, index) {
      if (
        null == row.damagedNum ||
        row.damagedNum == "" ||
        (row.damagedNum != "number" && isNaN(row.damagedNum))
      ) {
        row.damagedNum = 0;
      } else if (row.damagedNum <= 0) {
        row.damagedNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.damagedNum >= row.receivedNum) {
        row.damagedNum = 0;
        this.$message.warning("破损数不能大于已收数量");
      }
      this.$set(this.content.orderReturnCommodityList, index, {
        commodityId: row.commodityId,
        brand: row.brand,
        commodityName: row.commodityName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    changeDamage(row, type, index) {
      if (type > 0) {
        if (row.damagedNum >= row.receivedNum) {
          row.damagedNum = 0;
          this.$message.warning("已收数不能大于原单数量");
        } else {
          row.damagedNum++;
        }
      } else {
        row.damagedNum--;
        row.damagedNum > 0 ? row.damagedNum : (row.damagedNum = 0);
      }
      this.$set(this.content.orderReturnCommodityList, index, {
        commodityId: row.commodityId,
        brand: row.brand,
        commodityName: row.commodityName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    // 漏件
    changeCountMissing(row, index) {
      if (
        null == row.missingNum ||
        row.missingNum == "" ||
        (row.missingNum != "number" && isNaN(row.missingNum))
      ) {
        row.missingNum = 0;
      } else if (row.missingNum <= 0) {
        row.missingNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.missingNum > row.number) {
        row.missingNum = 0;
        this.$message.warning("已收数不能大于原单数量");
      } else if (
        parseInt(row.receivedNum) + parseInt(row.missingNum) >
        row.number
      ) {
        row.missingNum = 0;
        this.$message.warning("已收 + 漏件 不能大于原单数量");
      }

      this.$set(this.content.orderReturnCommodityList, index, {
        commodityId: row.commodityId,
        brand: row.brand,
        commodityName: row.commodityName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    changeMissing(row, type, index) {
      let addNum = parseInt(row.receivedNum) + parseInt(row.missingNum);
      if (type > 0) {
        if (row.missingNum >= row.number) {
          this.$message.warning("已收数不能大于原单数量");
        } else if (addNum >= row.number) {
          this.$message.warning("已收+漏件 不能大于原单数量");
        } else {
          row.missingNum++;
        }
      } else {
        row.missingNum--;
        row.missingNum > 0 ? row.missingNum : (row.missingNum = 0);
      }

      this.$set(this.content.orderReturnCommodityList, index, {
        commodityId: row.commodityId,
        brand: row.brand,
        commodityName: row.commodityName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });

      // console.log(this.content.orderReturnCommodityList);

      this.calculation();
    },
    /**
     * 商品已收 破损 漏件 数量操作修改
     **/

    /**
     * 赠品已收 破损 漏件 数量操作修改
     **/
    changCountRecivedZp(row, index) {
      if (
        null == row.receivedNum ||
        row.receivedNum == "" ||
        (row.receivedNum != "number" && isNaN(row.receivedNum))
      ) {
        row.receivedNum = 0;
      } else if (row.receivedNum <= 0) {
        row.receivedNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.receivedNum > row.number) {
        row.receivedNum = 0;
        this.$message.warning("已收数不能大于原单数量");
      } else if (
        parseInt(row.receivedNum) + parseInt(row.missingNum) >
        row.number
      ) {
        row.receivedNum = 0;
        this.$message.warning("已收 + 漏件 不能大于原单数量");
      }
      this.$set(this.content.orderReturnComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brand: row.brand,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    changeRecivedZp(row, type, index) {
      let addNum = parseInt(row.receivedNum) + parseInt(row.missingNum);
      if (type > 0) {
        if (row.receivedNum >= row.number) {
          this.$message.warning("已收数不能大于原单数量");
        } else if (addNum >= row.number) {
          this.$message.warning("已收+漏件 不能大于原单数量");
        } else {
          row.receivedNum++;
        }
      } else {
        row.receivedNum--;
        row.receivedNum > 0 ? row.receivedNum : (row.receivedNum = 0);
      }
      this.$set(this.content.orderReturnComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brand: row.brand,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    // 破损
    changeCountDamageZp(row, index) {
      if (
        null == row.damagedNum ||
        row.damagedNum == "" ||
        (row.damagedNum != "number" && isNaN(row.damagedNum))
      ) {
        row.damagedNum = 0;
      } else if (row.damagedNum <= 0) {
        row.damagedNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.damagedNum >= row.receivedNum) {
        row.damagedNum = 0;
        this.$message.warning("已收数不能大于已收数量");
      }
      this.$set(this.content.orderReturnComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brand: row.brand,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    changeDamageZp(row, type, index) {
      if (type > 0) {
        if (row.damagedNum >= row.receivedNum) {
          row.damagedNum = 0;
          this.$message.warning("已收数不能大于已收数量");
        } else {
          row.damagedNum++;
        }
      } else {
        row.damagedNum--;
        row.damagedNum > 0 ? row.damagedNum : (row.damagedNum = 0);
      }
      this.$set(this.content.orderReturnComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brand: row.brand,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    // 漏件
    changeCountMissingZp(row, index) {
      if (
        null == row.missingNum ||
        row.missingNum == "" ||
        (row.missingNum != "number" && isNaN(row.missingNum))
      ) {
        row.missingNum = 0;
      } else if (row.missingNum <= 0) {
        row.missingNum = 0;
        this.$message.warning("已经减到最低了哦");
      } else if (row.missingNum > row.number) {
        row.missingNum = 0;
        this.$message.warning("已收数不能大于原单数量");
      } else if (
        parseInt(row.receivedNum) + parseInt(row.missingNum) >
        row.number
      ) {
        row.missingNum = 0;
        this.$message.warning("已收 + 漏件 不能大于原单数量");
      }
      this.$set(this.content.orderReturnComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brand: row.brand,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    changeMissingZp(row, type, index) {
      let addNum = parseInt(row.receivedNum) + parseInt(row.missingNum);
      if (type > 0) {
        if (row.missingNum >= row.number) {
          this.$message.warning("已收数不能大于原单数量");
        } else if (addNum >= row.number) {
          this.$message.warning("已收+漏件 不能大于原单数量");
        } else {
          row.missingNum++;
        }
      } else {
        row.missingNum--;
        row.missingNum > 0 ? row.missingNum : (row.missingNum = 0);
      }
      this.$set(this.content.orderReturnComplimentaryList, index, {
        complimentaryId: row.complimentaryId,
        brand: row.brand,
        complimentaryName: row.complimentaryName,
        number: row.number,
        price: row.price,
        specificationName: row.specificationName,
        total: row.total,
        receivedNum: row.receivedNum,
        damagedNum: row.damagedNum,
        missingNum: row.missingNum,
        waitNumber: row.waitNumber,
      });
      this.calculation();
    },
    /**
     * 赠品已收 破损 漏件 数量操作修改
     **/
    /**
     * 统计已收，破损，漏件
     **/
    calculation() {
      let receivedTotal = 0;
      let damagedTotal = 0;
      let missingTotal = 0;
      let orginNumber = 0;

      for (let i = 0; i < this.content.orderReturnCommodityList.length; i++) {
        receivedTotal += Number(
          this.content.orderReturnCommodityList[i].receivedNum
        );
        damagedTotal += Number(
          this.content.orderReturnCommodityList[i].damagedNum
        );
        missingTotal += Number(
          this.content.orderReturnCommodityList[i].missingNum
        );
        orginNumber += Number(this.content.orderReturnCommodityList[i].number);
      }

      this.orginNumber = orginNumber;
      this.together = receivedTotal + missingTotal;

      let receivedTotalZp = 0;
      let damagedTotalZp = 0;
      let missingTotalZp = 0;
      if (!this.is_null(this.content.orderReturnComplimentaryList)) {
        for (
          let i = 0;
          i < this.content.orderReturnComplimentaryList.length;
          i++
        ) {
          receivedTotalZp += Number(
            this.content.orderReturnComplimentaryList[i].receivedNum
          );
          damagedTotalZp += Number(
            this.content.orderReturnComplimentaryList[i].damagedNum
          );
          missingTotalZp += Number(
            this.content.orderReturnComplimentaryList[i].missingNum
          );
        }
      }

      this.receivedTogether = receivedTotal + receivedTotalZp;
      this.damagedTogether = damagedTotal + damagedTotalZp;
      this.missingTogether = missingTotal + missingTotalZp;

      this.backNumTotal = this.receivedTogether + this.missingTogether;
    },
    /**
     * 确定收货
     **/
    submitEvent(approvalStatus) {
      let commodityRequests = [];
      for (let i = 0; i < this.content.orderReturnCommodityList.length; i++) {
        // 统计商品信息
        let goods = {
          brokenNo: this.content.orderReturnCommodityList[i].missingNum,
          commodityId: this.content.orderReturnCommodityList[i].commodityId,
          destroyNo: this.content.orderReturnCommodityList[i].damagedNum,
          number: this.content.orderReturnCommodityList[i].number,
          objId: this.content.orderReturnCommodityList[i].objId,
          receivedNo: this.content.orderReturnCommodityList[i].receivedNum,
          orderType: this.content.orderReturnCommodityList[i].orderType,
        };
        commodityRequests.push(goods);
      }
      // console.log(commodityRequests);
      let complimentaryRequests = [];
      if (!this.is_null(this.content.orderReturnComplimentaryList)) {
        // 统计赠品信息
        for (
          let i = 0;
          i < this.content.orderReturnComplimentaryList.length;
          i++
        ) {
          let gifts = {
            brokenNo: this.content.orderReturnComplimentaryList[i].missingNum,
            complimentaryId: this.content.orderReturnComplimentaryList[i]
              .complimentaryId,
            destroyNo: this.content.orderReturnComplimentaryList[i].damagedNum,
            number: this.content.orderReturnComplimentaryList[i].number,
            receivedNo: this.content.orderReturnComplimentaryList[i]
              .receivedNum,
            total: this.content.orderReturnComplimentaryList[i].total,
            objId: this.content.orderReturnComplimentaryList[i].objId,
          };
          complimentaryRequests.push(gifts);
        }
      }

      if (this.backNumTotal > 0) {
        let title = "";
        if (approvalStatus == 1) {
          title = "确定【驳回】收货";
        } else {
          title = "确定【确认】收货";
        }

        this.$msgbox({
          title: title,
          message:
            "总 计 : 已收" +
            this.receivedTogether +
            "件, 破损 : " +
            this.damagedTogether +
            "件, 漏件 : " +
            this.missingTogether +
            " 件",
          showCancelButton: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          beforeClose: (action, instance, done) => {
            if (action === "confirm") {
              instance.confirmButtonLoading = true;
              instance.confirmButtonText = "执行中...";
              setTimeout(() => {
                done();
                setTimeout(() => {
                  instance.confirmButtonLoading = false;
                }, 300);
              }, 1000);
            } else {
              done();
            }
          },
        })
          .then((res) => {
            this.logisticsCompany = this.content.logisticsCompany;
            this.logistCode = this.content.parcelNumber;

            this.axios
              .post("/order/order/return/confirm/receipt", {
                request: {
                  approvalStatus: approvalStatus, // 2-通过 1-驳回
                  comment: this.textarea,
                  commodityReturnNumRequests: commodityRequests,
                  comolimentaryReturnNumRequests: complimentaryRequests,
                  returnOrderId: this.returnOrderId,
                  updatedBy: "",
                },
                version: "",
              })
              .then((res) => {
                console.log(res);
                if (res.code == 0) {
                  this.$message.success("提交成功");
                  this.$router.push({
                    name: "unusualOrder",
                    query: {
                      tabName: this.$route.query.tabName,
                    },
                  });
                } else {
                  this.$message.warning(res.message);
                }
              });
          })
          .catch(() => {});
      } else {
        this.$message.error("未填写收到货的数量情况");
      }
    },
    /**
     * 确定收货
     **/

    is_null(content) {
      if (content) {
        return false;
      } else {
        return true;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.div1 {
  margin-left: -16px;
  background: url(../../../assets/breadcrumb2.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #2d7edf;
}

.div2 {
  margin-left: -16px;
  background: url(../../../assets/breadcrumb1.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #fff;
}

.div3 {
  margin-left: -8px;
  background: url(../../../assets/breadcrumb3.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #2d7edf;
}

/deep/.el-table td,
.el-table th {
  text-align: center;
}

.container {
  .orderInfo {
    background: #fff;
    padding: 10px 20px;
    border-radius: 6px;

    .title {
      border-bottom: 2px solid #e3e7ec;
      color: #4168e7;
      font-weight: 500;
      font-size: 15px;
      padding: 10px 0px;
    }

    .content {
      .contentTemp {
        .fontTemp {
          margin-top: 10px;
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          padding: 5px 0px;

          p {
            span {
              color: #ff5656;
            }

            font-size: 14px;
            color: #666666;
          }

          > div {
            margin-left: 10px;

            /deep/.el-input__inner {
              height: 30px;
              line-height: 30px;
            }

            /deep/.el-input__icon {
              height: 30px;
              line-height: 30px;
            }
          }

          .span {
            color: #666666;
            font-weight: 400;
            line-height: 20px;
            font-size: 14px;
            margin-right: 40px;
            word-spacing: 8px;
          }

          .span1 {
            display: inline-block;
            width: 50px;
            text-align: justify;
            text-justify: distribute-all-lines;
            /*ie6-8*/
            text-align-last: justify;
            /* ie9*/
            -moz-text-align-last: justify;
            /*ff*/
            -webkit-text-align-last: justify;
            /*chrome 20+*/
          }

          @media screen and (-webkit-min-device-pixel-ratio: 0) {
            /* chrome*/
            .test1:after {
              content: ".";
              display: inline-block;
              width: 100%;
              overflow: hidden;
              height: 0;
            }
          }
        }
      }
    }
  }

  .goodDetail {
    background: #fff;
    padding: 10px 12px;
    margin-top: 10px;
    border-radius: 6px;

    .title {
      border-bottom: 2px solid #e3e7ec;
      color: #4168e7;
      font-weight: 500;
      font-size: 15px;
      padding: 10px 12px;
    }

    .totalAll {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
      padding: 10px;
      border-bottom: 1px solid #e3e7ec;

      span {
        margin-left: 30px;
        font-size: 14px;
        font-weight: 550;
      }
    }

    .total {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
      padding: 10px;

      span {
        font-size: 14px;
        font-weight: 500;
        color: #5276e9;
        font-weight: 600;
      }
    }
  }

  .remark {
    background: #fff;
    padding: 10px 20px;
    margin-top: 10px;
    border-radius: 6px;

    .title {
      border-bottom: 2px solid #e3e7ec;
      color: #4168e7;
      font-weight: 500;
      font-size: 15px;
      padding: 10px 0px;
      margin-bottom: 10px;
    }
  }

  .submit {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    display: flex;
    justify-content: flex-end;
    padding: 10px 20px;
    z-index: 100;
  }
}

.inputDeal {
  display: flex;
  justify-content: space-around;
  align-items: center;

  span {
    font-size: 13px;
  }
}

.inputDeal:nth-child(2) {
  margin: 8px 0;
}

.numer {
  /deep/.el-button {
    padding: 0;
    margin: 0;
    background: #fff;
    height: 18px;
    line-height: 18px;
    width: 22px;
    text-align: center;
    font-size: 10px;
    color: #333;
    // font-weight: bold;
  }

  /deep/.el-input-group__prepend {
    padding: 0;
    border-radius: 4px;
    border: 1px solid #d9d9d9;
  }

  /deep/ .el-input-group {
    width: 80px;
  }

  /deep/.el-input-group__append {
    padding: 0;
    border-radius: 4px;
    border: 1px solid #d9d9d9;
  }

  /deep/.el-input__inner {
    width: 80px;
    text-align: center;
    padding: 0;
    margin: 0 5px;
    height: 24px;
    line-height: 24px;
    background: #f2f2f2;
    border-radius: 4px;
    border: none;
    color: #666;
    font-size: 10px;
  }
}
</style>
